<template>
	<div>
		<van-nav-bar title="已接请求"></van-nav-bar>
		<div>
			<van-pull-refresh v-model="flashingOrder" @refresh="flashOrder" style="height: calc(100vh - 46px);overflow: scroll;">
				<van-list v-model:loading="loadingNewOrder" :finished="noMoreOrder" finished-text="没有更多了"
					@load="loadNewOrder">
					<van-cell v-for="(order,key) in orderList" :key="key">
						<AcceptedOrderCell :orderName="order.offer.title" :price="order.offer.price" :pubTime="order.startTime"
							:context="order.context" num="1" :oid="order.id" :statu="order.status"
							></AcceptedOrderCell>
					</van-cell>
				</van-list>
			</van-pull-refresh>
		</div>
	</div>
</template>

<script>
	import {
		showNotify
	} from 'vant';
	import url from '@/assets/url.json';
	import AcceptedOrderCell from '@/components/units/AcceptedOrderCell.vue';
	
	export default {
		components: {
			AcceptedOrderCell
		},
		data() {
			return {
				noMoreOrder: false,
				flashingOrder: false,
				loadingNewOrder: false,
				orderList: [],
				page: 0,
				limit: 5,
				payWays: [{
						name: '微信支付',
						label: 'wechat'
					},
					{
						name: '钱包支付',
						label: 'wallet'
					}
				],
				payWayShow: false,
				payPageShow: false,
				priceShow: '',
				orderOffers: '',
				resurl: url.ip + '/api-offer/order/payFromApi',
			}
		},
		methods: {
	
			flashOrder() {
				this.page = 1;
				this.noMoreOrder = false;
				this.orderList = [];
				this.pushOrder();
			},
	
			loadNewOrder() {
				this.page += 1;
				this.pushOrder();
			},
	
	
			pushOrder() {
				this.$axios({
					url: url.ip + '/api-offer' + '/order/accepted',
					method: 'GET',
					params: {
						page: this.page,
						limit: this.limit,
					},
					headers: {
						token: this.$cookies.get('token'),
					}
				}).then((res) => {
					if (res.data.code !== 0) {
						this.noMoreOrder = true;
						showNotify({
							type: 'danger',
							message: res.data.message
						});
					} else {
						if (res.data.data.length <= 0) {
							this.noMoreOrder = true;
						} else {
							for (let key in res.data.data) {
								this.orderList.push(res.data.data[key]);
							}
						}
					}
					this.loadingNewOrder = false;
					this.flashingOrder = false;
				}).catch(() => {
					this.loadingNewOrder = false;
					this.flashingOrder = false;
					this.noMoreOrder = true;
					showNotify({
						type: 'danger',
						message: "网络错误或未登录"
					});
				})
			}
		}
	}
</script>

<style>
</style>